<template>
  <view class="personalData flex flex-column align-center">
    <s-header-title ref="headerTitle" isDisplayBack title="个人资料" is-fixed background="#FFFFFF"
                    @getPageHeight="getPageHeight"></s-header-title>
    <view :style="{height:`${headerHeight}px`}"></view>
    <single-gap title="头像" margin="25rpx 0 0 0" @elementClick="goAvatarList">
      <view class="personalData_avatar flex align-center justify-end">
        <image-avater :src="`${personalData.avatar}`" :width="76" :height="76" class="mr_15"></image-avater>
        <text class="iconfont icon-ic_rightarrow fs_26"></text>
      </view>
    </single-gap>
    <single-gap title="姓名" margin="25rpx 0 0 0" @elementClick="openNamePopup">
      <view class="personalData_avatar flex align-center justify-end">
        <text class="personalData_avatar_text mr_15">
          {{ `${!!personalData.surname ? personalData.surname : ''}${!!personalData.daimyo ? personalData.daimyo : ''}` || '未设置'
          }}
        </text>
        <text class="iconfont icon-ic_rightarrow fs_26"></text>
      </view>
    </single-gap>
    <single-gap title="性别" margin="25rpx 0 0 0">
      <view class="personalData_avatar flex align-center justify-end">
        <text class="personalData_avatar_text mr_15">
          {{ personalData.gender == 1 ? '男' : '女' }}
        </text>
      </view>
    </single-gap>
    <single-gap title="称谓" margin="25rpx 0 0 0" color="#FF4206" v-if="personalData.is_my != 1"
                @elementClick="openRelationshipPopUp">
      <view class="personalData_avatar flex align-center justify-end">
        <text class="personalData_avatar_text mr_15" style="color: #FF4206">
          {{ personalData.remark || '未设置' }}
        </text>
        <text class="iconfont icon-ic_rightarrow fs_26" v-if="personalData.is_own != 1"></text>
      </view>
    </single-gap>
    <single-gap title="生日" margin="25rpx 0 0 0" @elementClick="openBetterCalendar">
      <view class="personalData_avatar flex align-center justify-end">
        <text class="personalData_avatar_text mr_15"
              v-if="!!personalData.date" :style="{
          color:personalData.time_type == 2 ? '#000000' : '#9F9F9F'
        }">
          {{ personalData.full_list.gregorian_date || '未设置' }}
        </text>
        <text class="personalData_avatar_text mr_15" v-if="!!personalData.date"
              :style="{
          color: personalData.time_type == 1 ? '#000000': '#9F9F9F'
        }">
          {{ personalData.full_list.ganzhi_year || '' }}{{ personalData.full_list.lunar_month || '未设置' }}
        </text>
        <!--        <text class="personalData_avatar_text mr_15"-->
        <!--              v-if="!personalData.birthday && !personalData.birthday.public_time && !personalData.birthday.lunar_day">-->
        <!--          {{ personalData.birthday.lunar_day || '未设置' }}-->
        <!--        </text>-->
        <text class="iconfont icon-ic_rightarrow fs_26"></text>
      </view>
    </single-gap>
    <single-gap title="纪念日" margin="25rpx 0 0 0" @elementClick="openCommemoration"
                v-if="!!personalData.memoryday_list && personalData.memoryday_list.length <= 0">
      <view class="personalData_avatar flex align-center justify-end">
        <text class="personalData_avatar_text mr_15">
          去编辑
        </text>
        <text class="iconfont icon-ic_rightarrow fs_26"></text>
      </view>
    </single-gap>
    <single-gap title="纪念日" margin="25rpx 0 0 0" @elementClick="openCommemorationEdit(item)"
                v-else-if="!!personalData.memoryday_list"
                v-for="(item,index) in personalData.memoryday_list" :key="index">
      <view class="personalData_avatar flex align-center justify-end">
        <view class="flex flex-column align-end" v-if="!!item.name">
          <text class="personalData_avatar_text mr_15">
            {{ item.name }}
          </text>
          <view class="personalData_avatar_text mr_15 flex align-center" v-if="!!item.date">
            <view :style="{
              color:item.date_type == 2 ? '#000000' : '#9F9F9F'
            }">
              {{ dayjs(item.date).format('YYYY年MM月DD日') }}
            </view>
            <view :style="{
              color:item.date_type == 1 ? '#000000' : '#9F9F9F'
            }">
              {{ item.lunar_date }}
            </view>
          </view>
        </view>
        <text class="personalData_avatar_text mr_15" v-else>
          去编辑
        </text>
        <text class="iconfont icon-ic_rightarrow fs_26"></text>
      </view>
    </single-gap>
    <single-gap title="生日/纪念日提醒设置" margin="25rpx 0 0 0" v-if="personalData.is_my != 1"
                @elementClick="goReminderSetting">
      <view class="personalData_avatar flex align-center justify-end" style="height: 100%">
        <text class="iconfont icon-ic_rightarrow fs_26"></text>
      </view>
    </single-gap>

    <single-gap title="更多" v-if="!ismore" margin="25rpx 0 0 0" padding="36rpx 0 36rpx 0" @elementClick="setMore">
      <view class="personalData_avatar flex align-center justify-end" style="height: 100%">
        <text class="iconfont icon-ic_rightarrow fs_26"></text>
      </view>
    </single-gap>
    <single-gap title="签名" v-if="ismore" margin="25rpx 0 0 0" @elementClick="goSignature">
      <view class="personalData_avatar flex align-center justify-end">
        <text class="personalData_avatar_text mr_15">
          {{ personalData.bio || '未设置' }}
        </text>
        <text class="iconfont icon-ic_rightarrow fs_26"></text>
      </view>
    </single-gap>
    <single-gap title="祖籍地" v-if="ismore" margin="25rpx 0 0 0" @elementClick="openAncestral(1)">
      <view class="personalData_avatar flex align-center justify-end">
        <view class="personalData_avatar_text flex flex-column align-end mr_15">
          <view>
            {{ personalData.ancestral_home || '未设置' }}
          </view>
          <view class="wh_380" style="text-align: end;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
            {{ personalData.ancestral_address }}
          </view>
        </view>
        <text class="iconfont icon-ic_rightarrow fs_26"></text>
      </view>
    </single-gap>
    <single-gap title="现居地" v-if="ismore && personalData.is_alive" margin="25rpx 0 0 0"
                @elementClick="openAncestral(2)">
      <view class="personalData_avatar flex align-center justify-end">
        <view class="personalData_avatar_text mr_15 flex align-end flex-column">
          <view>{{ personalData.current_residence || '未设置' }}</view>
          <view class="wh_380" style="text-align: end;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
            {{ personalData.current_residence_address }}
          </view>
        </view>
        <text class="iconfont icon-ic_rightarrow fs_26"></text>
      </view>
    </single-gap>
    <!--    <picker :range="bloodList" range-key="label">-->
    <!--      <single-gap title="血型" v-if="ismore" margin="25rpx 0 0 0" @elementClick="setHemiform">-->
    <!--        <view class="personalData_avatar flex align-center justify-end">-->
    <!--          <text class="personalData_avatar_text mr_15">-->
    <!--            {{ personalData.blood_type || '未设置' }}-->
    <!--          </text>-->
    <!--          <text class="iconfont icon-ic_rightarrow fs_26"></text>-->
    <!--        </view>-->
    <!--      </single-gap>-->
    <!--    </picker>-->
    <single-gap title="学历" v-if="ismore" margin="25rpx 0 0 0" @elementClick="setDducationalBackground">
      <view class="personalData_avatar flex align-center justify-end">
        <text class="personalData_avatar_text mr_15">
          {{ personalData.edu_background || '未设置' }}
        </text>
        <text class="iconfont icon-ic_rightarrow fs_26"></text>
      </view>
    </single-gap>
    <single-gap title="职业" v-if="ismore" margin="25rpx 0 0 0" @elementClick="openOccupationalPopup">
      <view class="personalData_avatar flex align-center justify-end">
        <text class="personalData_avatar_text mr_15">
          {{ personalData.career || '未设置' }}
        </text>
        <text class="iconfont icon-ic_rightarrow fs_26"></text>
      </view>
    </single-gap>
    <single-gap title="在世" margin="25rpx 0 0 0" v-if="ismore && personalData.is_my != 1">
      <view class="flex justify-end">
        <su-switch v-model="personalData.is_alive"
                   size="40"
                   :bg="'bg_FF4206'"
                   @change="setAlice($event)"
        ></su-switch>
      </view>
    </single-gap>
    <single-gap title="祭日" v-if="ismore && !personalData.is_alive" margin="25rpx 0 0 0"
                @elementClick="openBetterCalendarDie">
      <view class="personalData_avatar flex align-center justify-end">
        <text class="personalData_avatar_text mr_15" v-if="!!personalData.dieday" :style="{
          color:personalData.is_lunar_die == 2 ? '#000000' : '#9F9F9F'
        }">
          {{ dayjs(personalData.dieday).format('YYYY年MM月DD日') || '未设置' }}
        </text>
        <text class="personalData_avatar_text mr_15" v-if="!!personalData.lunar_dieday" :style="{
          color: personalData.is_lunar_die == 1 ? '#000000': '#9F9F9F'
        }">
          {{ personalData.lunar_dieday || '未设置' }}
        </text>
        <text class="personalData_avatar_text mr-15"
              v-if="!personalData.dieday && !personalData.lunar_dieday">
          {{ personalData.lunar_dieday || '未设置' }}
        </text>
        <text class="iconfont icon-ic_rightarrow fs-26"></text>
      </view>
    </single-gap>
    <single-gap title="墓地" v-if="ismore && !personalData.is_alive" margin="25rpx 0 0 0"
                @elementClick="openAncestral(0)">
      <view class="personalData_avatar flex align-center justify-end">
        <view class="personalData_avatar_text mr_15 flex align-end flex-column">
          <view>{{ personalData.current_residence || '未设置' }}</view>
          <view class="wh_380" style="text-align: end;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
            {{ personalData.current_residence_address }}
          </view>
        </view>
        <text class="iconfont icon-ic_rightarrow fs_26"></text>
      </view>
    </single-gap>

    <textare-gap title="个人简介" margin="25rpx 0 0 0" :value="personalData.description" :options="options"
                 :personalData="personalData" @closeFeatured="closeFeatured"></textare-gap>
    <view class="personalData_bottomEdit mt_70" v-if="personalData.is_my != 1" @click="deleteMember">
      <text class="personalData_bottomEdit_text">
        删除{{ !!personalData.username ? personalData.username : personalData.remark }}
      </text>
    </view>
    <view style="height: 150rpx"></view>

    <first_popup ref="relationshipPopup">
      <template #content>
        <scroll-view :scroll-y="true" class="relationshipPopup ">
          <view class="relationshipPopup_all justify-between mt_44">
            <view class="relationshipPopup_all_list flex align-center justify-center"
                  v-for="(item,index) in relationshipsList"
                  :key="index" :style="{
                    background:relationshipsIndex == index ? '#FF4206':'#E5E5E5'
                  }" @click="selectRelation(index)">
              <text class="relationshipPopup_all_list_text" :style="{
                color:relationshipsIndex == index ? '#FFFFFF' :item.sexFlag ? '#292929': '#FF4206'
              }">{{ item.name }}
              </text>
            </view>
          </view>
        </scroll-view>
      </template>
      <template v-slot:bottomContent>
        <view class="relationshipPopup_bottomContent flex align-center justify-center  mt_48 mb_120 mr_19">
          <input class="relationshipPopup_bottomContent_input" v-model="callValue" placeholder="自定义填写"
                 placeholder-class="relationshipPopup_bottomContent_placeholder" @input="callInput"></input>
        </view>
      </template>
    </first_popup>

    <!-- 名字修改 -->
    <first_popup ref="namePopUp" @closePopup="namePopupClose">
      <template #content>
        <view class="familyMemberPopUp flex flex-column align-center">
          <view class="familyMemberPopUp_title mt_45">
            <view class="familyMemberPopUp_title_name">
              修改姓名
            </view>
          </view>
          <image class="familyMemberPopUp_icon z-1" :src="`${IMG_URL}add_icon.png`"></image>
          <view class="familyMemberPopUp_editInfo flex align-center justify-between mt_64">
            <view class="familyMemberPopUp_editInfo_left flex align-center justify-center">
              <input type="text" v-model="namePopupFrom.suername"
                     :placeholder="'尊姓'"
                     placeholder-class="familyMemberPopUp_editInfo_placeholder" @input="suernameInput"
                     :focus="suernameFocus"
                     @blur="surnameBlur">
            </view>
            <view class="familyMemberPopUp_editInfo_right flex align-center justify-center">
              <input type="text" v-model="namePopupFrom.name"
                     :placeholder="'大名'"
                     placeholder-class="familyMemberPopUp_editInfo_placeholder" @input="nameInput" @blur="nameBlur">
            </view>
          </view>
        </view>
      </template>
    </first_popup>
    <!-- 选择生日 -->
    <better-calendar class="z-999"
                     ref="betterCalendarRef"
                     :defaultType="defaultType"
                     :defaultValue="defaultValue"
                     :showCalendar="showCalendar"
                     @confirm="updateMemberBirthday"
                     @cancel="closeBetterCalendar"
    ></better-calendar>
    <!-- 选择祭日 -->
    <SBetterCalendar class="z-999"
                     ref="betterCalendarRefDie"
                     :defaultType="defaultDieType"
                     :defaultValue="defaultDieValue"
                     :isLeap="defaultDieLeap"
                     :showCalendar="showDieCalendar"
                     @confirm="updateMemberDie"
                     @cancel="cancelADie"
    ></SBetterCalendar>
    <!-- 选择祖籍地 -->
    <su-region-picker title="选择祖籍地"
                      :show="areaWindowDisplay"
                      @cancel="areaWindowDisplay = false"
                      @confirm="onRegionConfirm"
    ></su-region-picker>
    <!-- 选择现居地 -->
    <su-region-picker title="选择现居地"
                      :show="presentAddress"
                      @cancel="presentAddress = false"
                      @confirm="onAddressConfirm"
    ></su-region-picker>
    <!-- 选择墓地 -->
    <su-region-picker title="选择墓地"
                      :show="areaWindowDisplayDie"
                      @cancel="areaWindowDisplayDie = false"
                      @confirm="onRegionDieConfirm"
    ></su-region-picker>
    <!-- 选择血型 -->
    <!--    <u-select title="请选择血型" v-model="bloodTypeShow" :list="bloodList" @cancel="bloodTypeShow = false"-->
    <!--              @confirm="bloodTypeConfirm"></u-select>-->
    <!--    &lt;!&ndash; 选择学历 &ndash;&gt;-->
    <su-select title="请选择学历" :show-select="academicQualificationsShow" :list="[{list:academicQualificationsList}]"
               @cancel="academicQualificationsShow = false" @confirm="academicQualificationsConfirm"></su-select>
    <!--  职业修改  -->
    <first_popup ref="occupationalPopup" @closePopup="occupationFocusClose">
      <template #content>
        <view class="familyMemberPopUp_title mt_45">
          <view class="familyMemberPopUp_title_name">
            修改职业
          </view>
        </view>
        <image class="familyMemberPopUp_icon z-1" :src="`${IMG_URL}add_icon.png`"></image>
        <view class="occupationPopup">
          <input v-model="occupation" class="occupationPopup_input" placeholder="请输入职业名称"
                 :focus="occupationFocus" maxlength="10"></input>
        </view>
      </template>
    </first_popup>
  </view>
</template>

<script>
  import First_popup from '@/pages/familyPage/components/first_popup.vue';
  import HeaderTitle from '@/pages/familyPage/components/headerTitle.vue';
  import ImageAvater from '@/sheep/components/s-avatar/s-avatar.vue';
  import dayjs from 'dayjs';
  import SingleGap from '@/pages/familyPage/components/singleGap.vue';
  import BetterCalendar from '@/sheep/components/s-better-calendar/s-better-calendar.vue';
  import TextareGap from '@/pages/familyPage/components/textareGap.vue';
  import sheep from '@/sheep';
  import { calendar } from '@/sheep/components/s-better-calendar/calendar';
  import SuRegionPicker from '@/sheep/ui/su-region-picker/su-region-picker.vue';
  import Gapbar from '@/pages/genealogy/components/gapbar.vue';
  import SuSwitch from '@/sheep/ui/su-switch/su-switch.vue';
  import SBetterCalendar from '@/sheep/components/s-better-calendar/s-better-calendar.vue';
  import SuSelect from '@/pages/familyPage/components/su-select.vue';

  export default {
    components: {
      SuSelect,
      SBetterCalendar,
      Gapbar,
      SuRegionPicker,
      BetterCalendar,
      First_popup,
      TextareGap,
      ImageAvater,
      SingleGap,
      HeaderTitle,
      SuSwitch,
    },
    data() {
      const INIT_DAY_TYPE = 'solar';
      const INIT_DAY_TIMESTAMP = dayjs().valueOf();
      const INIT_DAY = dayjs().format('YYYY-MM-DD');
      return {
        showDieCalendar: false,
        defaultDieValue: [100, 0, 0],
        defaultDieType: 'solar',
        defaultDieLeap: false,
        // 头部高度
        headerHeight: 0,
        // 是否显示更多
        ismore: false,
        // 关系列表
        relationshipsList: [],
        relationshipsIndex: 0,
        // 关系自定义填写
        callValue: '',
        showCalendar: false,
        date: {
          type: INIT_DAY_TYPE, // 类型
          timestamp: INIT_DAY_TIMESTAMP, // 时间戳
          solarDate: INIT_DAY, // 公历日期 - 文本（2000-1-1）
          lunarDate: '', // 农历日期 - 文本（己卯年冬月廿五(2000-1-1)）
          lunarDateNumber: '', // 农历生日的数字写法（1999-12-25）
        },
        // 个人用户信息
        personalData: {},
        // 弹窗姓名输入框
        namePopupFrom: {
          suername: '',
          name: '',
        },
        areaWindowDisplay: false,
        presentAddress: false,
        areaWindowDisplayDie: false,
        addressInfo: [],
        selectAddress: 1,
        // 血型
        bloodTypeShow: false,
        // 血型列表
        bloodList: [
          {
            value: 'A',
            label: 'A',
          },
          {
            value: 'B',
            label: 'B',
          },
          {
            value: 'AB',
            label: 'AB',
          },
          {
            value: 'O',
            label: 'O',
          },
        ],
        // 学历
        academicQualificationsShow: false,
        // 学历列表
        academicQualificationsList: [
          {
            value: '无',
            label: '无',
          },
          {
            value: '小学',
            label: '小学',
          },
          {
            value: '初中',
            label: '初中',
          },
          {
            value: '高中',
            label: '高中',
          },
          {
            value: '专科',
            label: '专科',
          },
          {
            value: '本科',
            label: '本科',
          },
          {
            value: '研究生',
            label: '研究生',
          },
          {
            value: '博士',
            label: '博士',
          },
          {
            value: '博士后',
            label: '博士后',
          },
        ],
        // 职业输入框
        occupation: '',
        defaultValue: [100, 0, 0],
        defaultType: 'solar',
        suernameFocus: false,
        occupationFocus: false,
      };
    },
    props: {
      options: {
        type: Object,
        default: () => {
          return {};
        },
      },
    },
    watch: {
      personalData: {
        deep: true,
        handler(newValue, oldValue) {
          console.log('已经改变的参数=>', this.personalData.full_list, this.defaultType);

          if (!!this.personalData.full_list.gregorian_date) {
            if (this.defaultType == 'solar') {
              this.defaultValue = [Number(this.personalData.full_list.gregorian_year.split('-')[0]) - 1900, Number(this.personalData.full_list.gregorian_year.split('-')[1] - 1), Number(this.personalData.full_list.gregorian_year.split('-')[2] - 1)];
            } else {
              let lunar = calendar.solar2lunar(Number(this.personalData.full_list.gregorian_year.split('-')[0]), Number(this.personalData.full_list.gregorian_year.split('-')[1]), Number(this.personalData.full_list.gregorian_year.split('-')[2]));
              console.log(lunar);
              let date = calendar.lunar2solar(lunar.lYear, lunar.lMonth, lunar.lDay, lunar.isLeap);
              let leapMonth = calendar.leapMonth(this.personalData.full_list.gregorian_year.split('-')[0]);
              console.log('date=>', date, leapMonth);
              if (leapMonth != 0) {
                if (leapMonth < this.personalData.full_list.gregorian_year.split('-')[1]) {
                  this.defaultValue = [Number(date.lYear - 1900), Number(date.lMonth), Number(date.lDay) - 1];
                } else if (leapMonth == this.personalData.full_list.gregorian_year.split('-')[1] && date.isLeap) {
                  this.defaultValue = [Number(date.lYear - 1900), Number(date.lMonth), Number(date.lDay) - 1];
                } else if (leapMonth == this.personalData.full_list.gregorian_year.split('-')[1] && !date.isLeap) {
                  this.defaultValue = [Number(date.lYear - 1900), Number(date.lMonth) - 1, Number(date.lDay) - 1];
                } else {
                  this.defaultValue = [Number(date.lYear - 1900), Number(date.lMonth) - 1, Number(date.lDay) - 1];
                }
              } else {
                this.defaultValue = [Number(date.lYear - 1900), Number(date.lMonth) - 1, Number(date.lDay) - 1];
              }
            }
            this.date.isLeap = this.personalData.full_list.time_type == 2 ? true : false;
            this.$refs.betterCalendarRef.setPicker(this.defaultValue, this.defaultType, this.personalData.full_list.time_type == 2);
          }
        },
      },
    },
    computed: {
      IMG_URL() {
        return sheep.$store('AI').sq_image_path;
      },
      nc_image() {
        return sheep.$store('AI').nc_image;
      },
    },
    mounted() {
      if (this.options.is_use == 1) {
        this.ismore = true;
      }
    },
    methods: {
      // 获取家庭成员详情
      async getPersonalData() {
        let { data } = await sheep.$api.family.getFamilyMemberDetail({
          member_id: this.options.member_id,
          is_use: !this.options.is_use ? 0 : 1,
        });
        this.personalData = data;
        this.defaultType = this.personalData.time_type != 1 ? 'solar' : 'lunar';
        data.is_alive = !!data.is_alive ? data.is_alive : 1;
        this.personalData.is_alive = data.is_alive == 1 ? true : false;
      },
      // 获取称谓列表
      async getRelationshipsList() {
        const { data } = await sheep.$api.family.getFamilyRemarksList();
        console.log(data);
        this.relationshipsList = data;
      },
      setHemiform() {
        this.bloodTypeShow = true;
      },
      async setDducationalBackground() {
        const { data } = await sheep.$api.user.getEducationList();
        this.academicQualificationsList = data;
        this.academicQualificationsShow = true;
      },
      dayjs,
      // 处理用户名的输入事件
      suernameInput(e) {
        if (e.detail.value.length > 1) {
          let arr;
          arr = e.detail.value.match(/[\u4e00-\u9fa5]/g);
          if (!!arr) {
            this.$set(this.namePopupFrom, 'suername', arr.join('').substring(0, 2));
          } else {
            this.$set(this.namePopupFrom, 'suername', '');
          }
        }
      },
      // 用于处理用户名的输入失去焦点事件
      surnameBlur(e) {
        this.$set(this.namePopupFrom, 'suername', e.detail.value);
        // if (e.target.value.length > 0) {
        //   let arr
        //   arr = e.target.value.match(/[\u4e00-\u9fa5]/g)
        //   if (!!arr) {
        //     this.$set(this.namePopupFrom, 'suername', arr.join('').substring(0, 2))
        //   } else {
        //     this.$set(this.namePopupFrom, 'suername', '')
        //   }
        // }
      },
      nameInput(e) {
        if (e.detail.value.length > 1) {
          let arr;
          arr = e.detail.value.match(/[\u4e00-\u9fa5]/g);
          if (!!arr) {
            this.$set(this.namePopupFrom, 'name', arr.join('').substring(0, 4));
          } else {
            this.$set(this.namePopupFrom, 'name', '');
          }
        }
      },
      nameBlur(e) {
        this.$set(this.namePopupFrom, 'name', e.detail.value);
        // if (e.target.value.length > 0) {
        //   let arr
        //   arr = e.target.value.match(/[\u4e00-\u9fa5]/g)
        //   if (!!arr) {
        //     this.$set(this.namePopupFrom, 'name', arr.join('').substring(0, 4))
        //   } else {
        //     this.$set(this.namePopupFrom, 'name', '')
        //   }
        // }
      },
      getPageHeight(number) {
        this.headerHeight = number;
      },
      // 打开设置关系弹窗
      async openRelationshipPopUp() {
        if (this.options.is_use != 1) {
          const { code, msg } = await sheep.$api.family.checkAuth({
            family_id: this.options.family_id,
            action: 'add',
          });
          if (code != 1) {
            sheep.$helper.toast(msg);
            return;
          }
          this.$refs.relationshipPopup.openPopup({
            title: '设置称谓',
            maskClick: false,
            bottomContentWidth: '143rpx',
            confirm: () => {
              sheep.$api.family.updateFamilyMemberInfo({
                member_id: this.personalData.id,
                remark: this.relationshipsIndex != -1 ? this.relationshipsList[this.relationshipsIndex].name : this.callValue,
              }).then(res => {
                this.getPersonalData();
                this.$refs.relationshipPopup.closePopup();
                this.callValue = '';
                this.relationshipsIndex = 0;
                uni.showToast({
                  title: '设置成功',
                  icon: 'none',
                });
              });
            },
          });
        } else {
          this.$refs.relationshipPopup.openPopup({
            title: '设置称谓',
            maskClick: false,
            bottomContentWidth: '143rpx',
            confirm: () => {
              sheep.$api.family.updateFamilyMemberInfo({
                member_id: this.personalData.id,
                remark: this.relationshipsIndex != -1 ? this.relationshipsList[this.relationshipsIndex].name : this.callValue,
              }).then(res => {
                this.getPersonalData();
                this.$refs.relationshipPopup.closePopup();
                this.callValue = '';
                this.relationshipsIndex = 0;
                uni.showToast({
                  title: '设置成功',
                  icon: 'none',
                });
              });
            },
          });
        }
      },
      //
      setShowCalender() {
        this.showCalendar = false;
      },
      //
      async openBetterCalendar() {
        if (this.options.is_use != 1) {
          const { code, msg } = await sheep.$api.family.checkAuth({
            family_id: this.options.family_id,
            action: 'add',
          });
          if (code != 1) {
            sheep.$helper.toast(msg);
            return;
          }
          if (!this.personalData.full_list.gregorian_year) {
            this.showCalendar = true;
            return;
          }
          let birthday = dayjs(this.personalData.full_list.gregorian_year).format('YYYY-MM-DD');
          let dateArr = birthday.split('-');
          dateArr[0] = Number(dateArr[0]) - 1900;
          dateArr[1] = Number(dateArr[1]);
          dateArr[2] = Number(dateArr[2]);
          // await this.$refs.betterCalendarRef.setPicker(this.defaultValue, this.defaultType, this.personalData.time_type != 2 ? false : true);
          if (this.personalData.time_type == 1) {
            let dayInfo = calendar.solar2lunar(dayjs(birthday).year(), dayjs(birthday).month() + 1, dayjs(birthday).date());
            console.log(dayInfo);
            dateArr[0] = Number(dayInfo.lunarDate.split('-')[0]) - 1900;
            dateArr[1] = Number(dayInfo.lunarDate.split('-')[1]) - 1;
            dateArr[2] = Number(dayInfo.lunarDate.split('-')[2]) - 1;
            let day = calendar.leapMonth(Number(dateArr[0]) + 1900);
            if (!!dayInfo.isLeap) {
              let arr = [dateArr[0], dateArr[1] + 1, dateArr[2]];
              await this.$refs.betterCalendarRef.setPicker(arr, 'lunar', dayInfo.isLeap);
            } else {
              if (day <= 0) {
                await this.$refs.betterCalendarRef.setPicker(dateArr, 'lunar', dayInfo.isLeap);
              } else {
                if (dateArr[1] > day) {
                  let arr = [dateArr[0], dateArr[1] + 1, dateArr[2]];
                  await this.$refs.betterCalendarRef.setPicker(arr, 'lunar', dayInfo.isLeap);
                } else {
                  if (dayInfo.isLeap) {
                    let arr = [dateArr[0], dateArr[1] + 1, dateArr[2]];
                    await this.$refs.betterCalendarRef.setPicker(arr, 'lunar', dayInfo.isLeap);
                  } else {
                    await this.$refs.betterCalendarRef.setPicker([dateArr[0], dateArr[1], dateArr[2]], 'lunar', dayInfo.isLeap);
                  }
                }

              }
            }
          } else {
            let arr = [];
            arr[0] = Number(this.personalData.full_list.gregorian_year.split('-')[0] - 1900);
            arr[1] = Number(this.personalData.full_list.gregorian_year.split('-')[1]) - 1;
            arr[2] = Number(this.personalData.full_list.gregorian_year.split('-')[2]) - 1;
            await this.$refs.betterCalendarRef.setPicker(arr, 'solar', false);
          }
          this.showCalendar = true;
        } else {
          if (!this.personalData.full_list.gregorian_year) {
            this.showCalendar = true;
            return;
          }
          let birthday = dayjs(this.personalData.full_list.gregorian_year).format('YYYY-MM-DD');
          let dateArr = birthday.split('-');
          dateArr[0] = Number(dateArr[0]) - 1900;
          dateArr[1] = Number(dateArr[1]);
          dateArr[2] = Number(dateArr[2]);
          // await this.$refs.betterCalendarRef.setPicker(this.defaultValue, this.defaultType, this.personalData.time_type != 2 ? false : true);
          if (this.personalData.time_type == 1) {
            let dayInfo = calendar.solar2lunar(dayjs(birthday).year(), dayjs(birthday).month() + 1, dayjs(birthday).date());
            console.log(dayInfo);
            dateArr[0] = Number(dayInfo.lunarDate.split('-')[0]) - 1900;
            dateArr[1] = Number(dayInfo.lunarDate.split('-')[1]) - 1;
            dateArr[2] = Number(dayInfo.lunarDate.split('-')[2]) - 1;
            let day = calendar.leapMonth(Number(dateArr[0]) + 1900);
            if (!!dayInfo.isLeap) {
              let arr = [dateArr[0], dateArr[1] + 1, dateArr[2]];
              await this.$refs.betterCalendarRef.setPicker(arr, 'lunar', dayInfo.isLeap);
            } else {
              if (day <= 0) {
                await this.$refs.betterCalendarRef.setPicker(dateArr, 'lunar', dayInfo.isLeap);
              } else {
                if (dateArr[1] > day) {
                  let arr = [dateArr[0], dateArr[1] + 1, dateArr[2]];
                  await this.$refs.betterCalendarRef.setPicker(arr, 'lunar', dayInfo.isLeap);
                } else {
                  if (dayInfo.isLeap) {
                    let arr = [dateArr[0], dateArr[1] + 1, dateArr[2]];
                    await this.$refs.betterCalendarRef.setPicker(arr, 'lunar', dayInfo.isLeap);
                  } else {
                    await this.$refs.betterCalendarRef.setPicker([dateArr[0], dateArr[1], dateArr[2]], 'lunar', dayInfo.isLeap);
                  }
                }

              }
            }
          } else {
            let arr = [];
            arr[0] = Number(this.personalData.full_list.gregorian_year.split('-')[0] - 1900);
            arr[1] = Number(this.personalData.full_list.gregorian_year.split('-')[1]) - 1;
            arr[2] = Number(this.personalData.full_list.gregorian_year.split('-')[2]) - 1;
            await this.$refs.betterCalendarRef.setPicker(arr, 'solar', false);
          }
          this.showCalendar = true;
        }

      },
      async selectDate(e) {
        this.date = await {
          type: e.type,
          timestamp: this.$dayjs(e.solarDate).valueOf(),
          solarDate: e.solarDate,
          lunarDate: e.lunarDate,
          lunarDateNumber: e.lunarDateNumber,
          isLeap: e.isLeap, // 一年里是否有闰月
        };
        this.form.dateBirth = e.type == 'lunar' ? e.lunarDateNumber : e.solarDate;
        this.showCalendar = false;
      },
      async goReminderSetting() {
        const { code, msg } = await sheep.$api.family.checkAuth({
          family_id: this.options.family_id,
          action: 'add',
        });
        if (code != 1) {
          sheep.$helper.toast(msg);
          return;
        }
        sheep.$router.go('/pages/familyPage/reminderSettings', { member_id: this.personalData.id });
      },
      // 选中关系名称
      selectRelation(index) {
        this.callValue = '';
        this.relationshipsIndex = index;
      },
      // 自定义关系名称
      callInput(e) {
        this.relationshipsIndex = -1;
      },
      // 修改成员生日
      async updateMemberBirthday(e) {
        await sheep.$api.family.updateFamilyMemberInfo({
          member_id: this.personalData.id,
          time_type: e.type == 'lunar' ? 1 : 2,
          is_leap_month: e.isLeap ? 2 : 1,
          date: e.type == 'lunar' ? e.lunarDateNumber : e.solarDate,
        });
        uni.showToast({
          title: '修改成功',
          icon: 'none',
        });
        await this.getPersonalData();
        this.showCalendar = false;
      },
      // 选择头像
      async goAvatarList() {
        if (this.options.is_use == 1) {
          uni.$once('signature', () => {
            this.getPersonalData();
          });
          sheep.$router.go('/pages/familyPage/avatarsList', {
            member_id: this.personalData.id,
            sex: this.personalData.gender,
            is_family: 1,
            is_genealoy: 1,
          });
          return;
        }
        const { code, msg } = await sheep.$api.family.checkAuth({
          family_id: this.options.family_id,
          action: 'add',
        });
        if (code != 1) {
          sheep.$helper.toast(msg);
        } else {
          uni.$once('signature', () => {
            this.getPersonalData();
          });
          sheep.$router.go('/pages/familyPage/avatarsList', {
            member_id: this.personalData.id,
            sex: this.personalData.gender,
            is_family: 1,
            is_genealoy: 1,
          });
        }
      },
      // 修改名字
      async openNamePopup() {
        if (this.options.is_use != 1) {
          const { code, msg } = await sheep.$api.family.checkAuth({
            family_id: this.options.family_id,
            action: 'add',
          });
          if (code != 1) {
            sheep.$helper.toast(msg);
            return;
          }
          setTimeout(() => {
            this.suernameFocus = true;
          }, 100);
          this.namePopupFrom.suername = !!this.personalData.surname ? this.personalData.surname : '';
          this.namePopupFrom.name = !!this.personalData.daimyo ? this.personalData.daimyo : '';
          this.$refs.namePopUp.openPopup({
            title: '修改姓名',
            showTitle: false,
            maskClick: false,
            popupBackground: true,
            confirm: async () => {
              if (this.namePopupFrom.suername == '') {
                uni.showToast({
                  title: '姓氏尚未填写',
                  icon: 'none',
                });
                return;
              }
              if (this.namePopupFrom.name == '') {
                uni.showToast({
                  title: '名称尚未填写',
                  icon: 'none',
                });
                return;
              }
              let { code } = await sheep.$api.family.updateFamilyMemberInfo({
                member_id: this.personalData.id,
                surname: this.namePopupFrom.suername,
                daimyo: this.namePopupFrom.name,
              });
              if (code == 1) {
                this.suernameFocus = false;
                // this.$store.dispatch('setFamilyDetail');
                uni.showToast({
                  title: '修改成功',
                  icon: 'none',
                });
                this.$refs.namePopUp.closePopup();
                this.namePopupFrom.name = '';
                this.namePopupFrom.suername = '';
                await this.getPersonalData();
              }
            },
          });
        } else {
          setTimeout(() => {
            this.suernameFocus = true;
          }, 100);
          this.namePopupFrom.suername = !!this.personalData.surname ? this.personalData.surname : '';
          this.namePopupFrom.name = !!this.personalData.daimyo ? this.personalData.daimyo : '';
          this.$refs.namePopUp.openPopup({
            title: '修改姓名',
            showTitle: false,
            maskClick: false,
            popupBackground: true,
            confirm: async () => {
              if (this.namePopupFrom.suername == '') {
                uni.showToast({
                  title: '姓氏尚未填写',
                  icon: 'none',
                });
                return;
              }
              if (this.namePopupFrom.name == '') {
                uni.showToast({
                  title: '名称尚未填写',
                  icon: 'none',
                });
                return;
              }
              let { code } = await sheep.$api.family.updateFamilyMemberInfo({
                member_id: this.personalData.id,
                surname: this.namePopupFrom.suername,
                daimyo: this.namePopupFrom.name,
              });
              if (code == 1) {
                this.suernameFocus = false;
                // this.$store.dispatch('setFamilyDetail');
                uni.showToast({
                  title: '修改成功',
                  icon: 'none',
                });
                this.$refs.namePopUp.closePopup();
                this.namePopupFrom.name = '';
                this.namePopupFrom.suername = '';
                await this.getPersonalData();
              }
            },
          });
        }
      },
      namePopupClose() {
        this.suernameFocus = false;
      },
      closeFeatured() {
        this.getPersonalData();
      },
      // 修改签名
      async goSignature() {
        if (this.options.is_use != 1) {
          const { code, msg } = await sheep.$api.family.checkAuth({
            family_id: this.options.family_id,
            action: 'add',
          });
          if (code != 1) {
            sheep.$helper.toast(msg);
            return;
          }
          uni.$once('signature', () => {
            this.getPersonalData();
          });
          sheep.$router.go('/pages/familyPage/signature', {
            member_id: this.personalData.id,
            is_sign: 1,
            sigin: this.personalData.bio,
          });
        } else {
          uni.$once('signature', () => {
            this.getPersonalData();
          });
          sheep.$router.go('/pages/familyPage/signature', {
            member_id: this.personalData.id,
            is_sign: 1,
            sigin: this.personalData.bio,
          });
        }

      },
      // 添加纪念日
      async openCommemoration() {
        if (this.options.is_use != 1) {
          const { code, msg } = await sheep.$api.family.checkAuth({
            family_id: this.options.family_id,
            action: 'add',
          });
          if (code != 1) {
            sheep.$helper.toast(msg);
            return;
          }
        } else {
          sheep.$router.go('/pages/family/anniversary', { is_flag: 0, member_id: this.personalData.id });
        }
      },
      // 修改纪念日
      async openCommemorationEdit(item) {
        if (this.options.is_use != 1) {
          const { code, msg } = await sheep.$api.family.checkAuth({
            family_id: this.options.family_id,
            action: 'add',
          });
          if (code != 1) {
            sheep.$helper.toast(msg);
            return;
          }
          let time = '';
          if (item.date_type == 1) {
            if (!!item.date) {
              time = calendar.solar2lunar(dayjs(item.date).year(), dayjs(item.date).month() + 1, dayjs(item.date).date()).lunarDate;
            }
          } else {
            if (!!item.date) {
              time = item.date;
            }
          }

          sheep.$router.go('/pages/family/anniversary', {
            name: item.name || '',
            is_flag: 1,
            isEdit: 1,
            anniversaryId: item.id,
            member_id: item.member_id,
            username: item.member_username || item.member_remark,
            date: time,
            time_type: item.date_type,
            isLeapMonth: item.is_leap_month,
            family_id: item.family_id,
          });
        } else {
          let time = '';
          if (item.date_type == 1) {
            if (!!item.date) {
              time = calendar.solar2lunar(dayjs(item.date).year(), dayjs(item.date).month() + 1, dayjs(item.date).date()).lunarDate;
            }
          } else {
            if (!!item.date) {
              time = item.date;
            }
          }
          sheep.$router.go('/pages/family/anniversary', {
            name: item.name || '',
            is_flag: 1,
            isEdit: 1,
            anniversaryId: item.id,
            member_id: item.member_id,
            username: item.member_username || item.member_remark,
            date: time,
            time_type: item.date_type,
            isLeapMonth: item.is_leap_month,
            family_id: item.family_id,
          });
        }
      },
      // 选择地址弹窗
      async openAncestral(index) {
        if (this.options.is_use != 1) {
          const { code, msg } = await sheep.$api.family.checkAuth({
            family_id: this.options.family_id,
            action: 'add',
          });
          if (code != 1) {
            sheep.$helper.toast(msg);
            return;
          }
          sheep.$api.data.area().then((res) => {
            if (res.code === 1) {
              uni.setStorageSync('areaData', res.data);
            }
          });
          if (index == 0) {
            // this.areaWindowDisplayDie = true;
            sheep.$router.go('/pages/extend/addressFill', { id: this.personalData.id, type: 4 });
          } else if (index == 1) {
            // this.areaWindowDisplay = true;
            sheep.$router.go('/pages/extend/addressFill', { id: this.personalData.id, type: 2 });
          } else {
            // this.presentAddress = true;
            sheep.$router.go('/pages/extend/addressFill', { id: this.personalData.id, type: 3 });
          }
        } else {
          sheep.$api.data.area().then((res) => {
            if (res.code === 1) {
              uni.setStorageSync('areaData', res.data);
            }
          });
          if (index == 0) {
            // this.areaWindowDisplayDie = true;
            sheep.$router.go('/pages/extend/addressFill', { id: this.personalData.id, type: 4 });
          } else if (index == 1) {
            // this.areaWindowDisplay = true;
            sheep.$router.go('/pages/extend/addressFill', { id: this.personalData.id, type: 2 });
          } else {
            // this.presentAddress = true;
            sheep.$router.go('/pages/extend/addressFill', { id: this.personalData.id, type: 3 });
          }
        }
      },
      changeClose() {
        this.areaWindowDisplay = false;
      },
      async OnChangeAddress(address) {
        if (this.selectAddress == 1) {
          let { status, msg } = await updateMemberImage({
            member_id: this.personalData.id,
            city_list: address,
            ancestral: address.map(v => v.label).join('/'),
          });
          if (status == 200) {
            uni.showToast({
              title: '修改成功',
              icon: 'none',
            });
            this.getPersonalData(this.personalData.id);
            this.areaWindowDisplay = false;
          } else {
            uni.showToast({
              title: msg,
              icon: 'none',
            });
          }
        } else {
          let { status, msg } = await updateMemberImage({
            member_id: this.personalData.id,
            residence_list: address,
            current_address: address.map(v => v.label).join('/'),
          });
          if (status == 200) {
            uni.showToast({
              title: '修改成功',
              icon: 'none',
            });
            this.getPersonalData(this.personalData.id);
            this.areaWindowDisplay = false;
          } else {
            uni.showToast({
              title: msg,
              icon: 'none',
            });
          }
        }
      },
      setMore() {
        this.ismore = true;
      },
      // 确定选择血型
      async bloodTypeConfirm(e) {
        let { status, msg } = await updateMemberImage({
          member_id: this.personalData.id,
          blood_type: e[0].value,
        });
        if (status == 200) {
          uni.showToast({
            title: '修改成功',
            icon: 'none',
          });
          this.getPersonalData(this.personalData.id);
          this.bloodTypeShow = false;
        } else {
          uni.showToast({
            title: msg,
            icon: 'none',
          });
        }
      },
      // 确定选择学历
      async academicQualificationsConfirm(e) {
        const { code, msg } = await sheep.$api.family.updateFamilyMemberInfo({
          member_id: this.options.member_id,
          edu_background: this.academicQualificationsList[e[0]].edu_name,
        });
        if (code == 1) {
          uni.showToast({
            title: '修改成功',
            icon: 'none',
          });
          await this.getPersonalData();
          this.academicQualificationsShow = false;
        } else {
          uni.showToast({
            title: msg,
            icon: 'none',
          });
        }
      },
      // 设置职业
      async openOccupationalPopup() {
        if (this.options.is_use != 1) {
          const { code, msg } = await sheep.$api.family.checkAuth({
            family_id: this.options.family_id,
            action: 'add',
          });
          if (code != 1) {
            sheep.$helper.toast(msg);
            return;
          }
          this.occupation = this.personalData.career;
          setTimeout(() => {
            this.occupationFocus = true;
          }, 100);
          this.$refs.occupationalPopup.openPopup({
            title: '修改职业',
            showTitle: false,
            maskClick: false,
            popupBackground: true,
            confirm: async () => {
              console.log(this);
              if (!this.occupation) {
                uni.showToast({
                  title: '职业尚未填写',
                  icon: 'none',
                });
                return;
              }
              let { code } = await sheep.$api.family.updateFamilyMemberInfo({
                member_id: this.personalData.id,
                career: this.occupation,
              });
              this.occupationFocus = false;
              uni.showToast({
                title: '修改成功',
                icon: 'none',
              });
              this.occupation = '';
              await this.getPersonalData();
              this.$refs.occupationalPopup.closePopup();
            },
          });
          return;
        }
        setTimeout(() => {
          this.occupationFocus = true;
        }, 100);
        this.$refs.occupationalPopup.openPopup({
          title: '修改职业',
          showTitle: false,
          maskClick: false,
          popupBackground: true,
          confirm: async () => {
            console.log(this);
            if (!this.occupation) {
              uni.showToast({
                title: '职业尚未填写',
                icon: 'none',
              });
              return;
            }
            let { code } = await sheep.$api.family.updateFamilyMemberInfo({
              member_id: this.personalData.id,
              career: this.occupation,
            });
            this.occupationFocus = false;
            uni.showToast({
              title: '修改成功',
              icon: 'none',
            });
            this.occupation = '';
            await this.getPersonalData();
            this.$refs.occupationalPopup.closePopup();
          },
        });
      },
      async setAlice() {
        let { status, msg } = await sheep.$api.family.updateFamilyMemberInfo({
          member_id: this.personalData.id,
          is_alive: !!this.personalData.is_alive ? 1 : 2,
        });
        await this.getPersonalData();
      },
      occupationFocusClose() {
        this.occupationFocus = false;
      },
      async save(value) {
        if (!value) {
          uni.showToast({
            title: '备注尚未填写',
            icon: 'none',
          });
          return;
        }
        let { status, msg } = await updateMemberImage({
          member_id: this.personalData.id,
          notes: value,
        });
        if (status == 200) {
          uni.showToast({
            title: '修改成功',
            icon: 'none',
          });
          this.getPersonalData(this.personalData.id);
        } else {
          uni.showToast({
            title: msg,
            icon: 'none',
          });
        }
      },
      goNotePath() {
        this.$nav.navigateTo('/pages/shiqinUserPage/signature', { member_id: this.personalData.id, is_sign: 2 });
      },
      // 删除家庭成员
      async deleteMember() {
        const { code, msg } = await sheep.$api.family.checkAuth({
          family_id: this.options.family_id,
          action: 'add',
        });
        if (code != 1) {
          sheep.$helper.toast(msg);
          return;
        }
        uni.showModal({
          title: '删除家庭成员',
          content: '确定删除该家庭成员吗？',
          success: async (res) => {
            if (!!res.confirm) {
              let { code, msg } = await sheep.$api.family.delFamilyMember({ member_id: this.personalData.id });
              if (code == 1) {
                sheep.$helper.toast('删除成功');
                setTimeout(() => {
                  uni.navigateBack({
                    delta: 2,
                  });
                }, 1500);
              } else {
                sheep.$helper.toast(msg);
              }
            }
          },
        });
      },
      closeBetterCalendar() {
        this.showCalendar = false;
      },
      cancelADie() {
        this.showDieCalendar = false;
      },
      // 选择区域
      async onRegionConfirm(e) {
        console.log(e);
        const { data } = await sheep.$api.family.updateFamilyMemberInfo({
          member_id: this.personalData.id,
          ancestral_home: e.province_name + '-' + e.city_name + '-' + e.district_name,
        });
        uni.showToast({
          title: '修改成功',
          icon: 'none',
        });
        await this.getPersonalData();
        this.areaWindowDisplay = false;
      },

      // 选择现居地
      async onAddressConfirm(e) {
        const { data } = await sheep.$api.family.updateFamilyMemberInfo({
          member_id: this.personalData.id,
          current_residence: e.province_name + '-' + e.city_name + '-' + e.district_name,
        });
        uni.showToast({
          title: '修改成功',
          icon: 'none',
        });
        await this.getPersonalData();
        this.presentAddress = false;
      },
      async onRegionDieConfirm(e) {
        const { data } = await sheep.$api.family.updateFamilyMemberInfo({
          member_id: this.personalData.id,
          current_residence: e.province_name + '-' + e.city_name + '-' + e.district_name,
          // current_residence: [e.province_name, e.city_name, e.district_name],
        });
        await this.getPersonalData(this.personalData.id);
        this.areaWindowDisplayDie = false;
      },
      async openBetterCalendarDie() {
        if (this.options.is_use != 1) {
          const { code, msg } = await sheep.$api.family.checkAuth({
            family_id: this.options.family_id,
            action: 'add',
          });
          if (code != 1) {
            sheep.$helper.toast(msg);
            return;
          }
          if (!this.personalData.dieday) {
            this.showDieCalendar = true;
            return;
          }
          let birthday = dayjs(this.personalData.dieday).format('YYYY-MM-DD');
          let day = calendar.leapMonth(dayjs(birthday).year());
          if (this.personalData.is_lunar_die == 1) {
            let dayInfo = calendar.solar2lunar(dayjs(birthday).year(), dayjs(birthday).month() + 1, dayjs(birthday).date());
            // let isHaveIntercalaryMonth = 0;
            // if (calendar.leapMonth(dayInfo.lYear) != 0) {
            //   isHaveIntercalaryMonth = calendar.leapMonth(dayInfo.lYear)
            // }
            if (!!dayInfo.isLeap) {
              this.defaultDieValue = [
                dayInfo.lYear - 1900,
                dayInfo.lMonth,
                dayInfo.lDay - 1,
              ];
              this.defaultDieType = 'lunar';
              this.defaultDieLeap = true;
              this.$refs.betterCalendarRefDie.setPicker(this.defaultDieValue, this.defaultDieType, this.defaultDieLeap);
            } else {
              if (day <= 0) {
                let month = dayInfo.lMonth;
                this.defaultDieValue = [
                  dayInfo.lYear - 1900,
                  month - 1,
                  dayInfo.lDay - 1,
                ];
                this.defaultDieType = 'lunar';
                this.defaultDieLeap = false;
                this.$refs.betterCalendarRefDie.setPicker(this.defaultDieValue, this.defaultDieType);
              } else {
                let month = dayInfo.lMonth;
                this.defaultDieValue = [
                  dayInfo.lYear - 1900,
                  month > day ? month : month - 1,
                  dayInfo.lDay - 1,
                ];
                this.defaultDieType = 'lunar';
                this.defaultDieLeap = false;
                this.$refs.betterCalendarRefDie.setPicker(this.defaultDieValue, this.defaultDieType);
              }
            }
          } else {
            this.defaultDieType = 'solar';
            this.defaultDieValue = [
              dayjs(birthday).year() - 1900,
              dayjs(birthday).month(),
              dayjs(birthday).date() - 1,
            ];
            this.$refs.betterCalendarRefDie.setPicker(this.defaultDieValue, this.defaultDieType);
          }
          this.showDieCalendar = true;
        } else {
          if (!this.personalData.dieday) {
            this.showDieCalendar = true;
            return;
          }
          let birthday = dayjs(this.personalData.dieday).format('YYYY-MM-DD');
          let day = calendar.leapMonth(dayjs(birthday).year());
          if (this.personalData.is_lunar_die == 1) {
            let dayInfo = calendar.solar2lunar(dayjs(birthday).year(), dayjs(birthday).month() + 1, dayjs(birthday).date());
            // let isHaveIntercalaryMonth = 0;
            // if (calendar.leapMonth(dayInfo.lYear) != 0) {
            //   isHaveIntercalaryMonth = calendar.leapMonth(dayInfo.lYear)
            // }
            if (!!dayInfo.isLeap) {
              this.defaultDieValue = [
                dayInfo.lYear - 1900,
                dayInfo.lMonth,
                dayInfo.lDay - 1,
              ];
              this.defaultDieType = 'lunar';
              this.defaultDieLeap = true;
              this.$refs.betterCalendarRefDie.setPicker(this.defaultDieValue, this.defaultDieType, this.defaultDieLeap);
            } else {
              if (day <= 0) {
                let month = dayInfo.lMonth;
                this.defaultDieValue = [
                  dayInfo.lYear - 1900,
                  month - 1,
                  dayInfo.lDay - 1,
                ];
                this.defaultDieType = 'lunar';
                this.defaultDieLeap = false;
                this.$refs.betterCalendarRefDie.setPicker(this.defaultDieValue, this.defaultDieType);
              } else {
                let month = dayInfo.lMonth;
                this.defaultDieValue = [
                  dayInfo.lYear - 1900,
                  month > day ? month : month - 1,
                  dayInfo.lDay - 1,
                ];
                this.defaultDieType = 'lunar';
                this.defaultDieLeap = false;
                this.$refs.betterCalendarRefDie.setPicker(this.defaultDieValue, this.defaultDieType);
              }
            }
          } else {
            this.defaultDieType = 'solar';
            this.defaultDieValue = [
              dayjs(birthday).year() - 1900,
              dayjs(birthday).month(),
              dayjs(birthday).date() - 1,
            ];
            this.$refs.betterCalendarRefDie.setPicker(this.defaultDieValue, this.defaultDieType);
          }
          this.showDieCalendar = true;
        }

      },
      async updateMemberDie(e) {
        const { data } = await sheep.$api.family.updateFamilyMemberInfo({
          member_id: this.personalData.id,
          is_lunar_die: e.type == 'lunar' ? 1 : 2,
          dieday: e.type == 'lunar' ? e.lunarDateNumber : e.solarDate,
          isLeapMonths_die: e.isLeap ? 2 : 1,
        });
        this.showDieCalendar = false;
        await this.getPersonalData();
      },
    },

  };
</script>

<style lang="scss" scoped>
  .personalData {
    width: 750rpx;
    min-height: 100vh;
    background: #F5F5F5;
    margin: auto;

    .personalData_avatar {
      //width: 489rpx;

      .personalData_avatar_image {
        width: 30rpx;
        height: 30rpx;
      }

      .personalData_avatar_text {
        font-family: PingFang SC, PingFang SC;
        font-weight: 500;
        font-size: 26rpx;
        color: #A0A0A0;
      }
    }

    .personalData_bottomEdit {
      .personalData_bottomEdit_text {
        font-family: PingFang SC, PingFang SC;
        font-weight: 500;
        font-size: 24rpx;
        color: #A0A0A0;
      }
    }

    .relationshipPopup {
      width: 556rpx;
      max-height: 846rpx;

      .relationshipPopup_all {
        width: 556rpx;
        display: grid;
        grid-template-columns: repeat(3, 168rpx);
        grid-row-gap: 26rpx;

        .relationshipPopup_all_list {
          width: 168rpx;
          height: 63rpx;
          background: #E5E5E5;
          border-radius: 41rpx 41rpx 41rpx 41rpx;
        }
      }
    }

    .relationshipPopup_bottomContent {
      width: 393rpx;
      height: 80rpx;
      background: #FFFFFF;
      border-radius: 40rpx 40rpx 40rpx 40rpx;
      border: 1rpx solid #707070;

      .relationshipPopup_bottomContent_input {
        text-align: center;
      }

      .relationshipPopup_bottomContent_placeholder {
        font-family: PingFang SC, PingFang SC;
        font-weight: 500;
        font-size: 30rpx;
        color: #A0A0A0;
      }
    }

    .familyMemberPopUp {
      width: 506rpx;

      .familyMemberPopUp_title {
        width: 454rpx;

        .familyMemberPopUp_title_name {
          font-family: PingFang SC, PingFang SC;
          font-weight: 500;
          font-size: 48rpx;
          color: #292929;

        }

        .familyMemberPopUp_title_detail {
          font-family: PingFang SC, PingFang SC;
          font-weight: 500;
          font-size: 24rpx;
          color: #9F9F9F;
        }
      }

      .familyMemberPopUp_icon {
        width: 147rpx;
        height: 147rpx;
        position: absolute;
        top: 0;
        right: 0;
      }

      .familyMemberPopUp_scrollView {
        width: 506rpx;
        overflow: hidden;
        white-space: nowrap;

        .familyMemberPopUp_scrollView_list {
          display: inline-block;
        }
      }

      .familyMemberPopUp_editInfo {
        width: 506rpx;

        .familyMemberPopUp_editInfo_left {
          width: 239rpx;
          height: 80rpx;
          background: #FFFFFF;
          border-radius: 40rpx 40rpx 40rpx 40rpx;
          border: 2rpx solid #707070;

          input {
            text-align: center;
          }
        }

        .familyMemberPopUp_editInfo_right {
          width: 239rpx;
          height: 80rpx;
          background: #FFFFFF;
          border-radius: 40rpx 40rpx 40rpx 40rpx;
          border: 2rpx solid #707070;

          input {
            text-align: center;
          }
        }

        .familyMemberPopUp_editInfo_placeholder {
          font-family: PingFang SC, PingFang SC;
          font-weight: 500;
          font-size: 28rpx;
          color: #A0A0A0;
        }
      }
    }

    .occupationPopup {
      margin-top: 40rpx;
      width: 556rpx;

      .occupationPopup_input {
        width: 556rpx;
        height: 80rpx;
        border: 2rpx solid #707070;
        border-radius: 20rpx;
        text-align: center;
      }
    }

    .familyMemberPopUp_title {
      width: 454rpx;

      .familyMemberPopUp_title_name {
        font-family: PingFang SC, PingFang SC;
        font-weight: 500;
        font-size: 48rpx;
        color: #292929;

      }

      .familyMemberPopUp_title_detail {
        font-family: PingFang SC, PingFang SC;
        font-weight: 500;
        font-size: 24rpx;
        color: #9F9F9F;
      }
    }

    .familyMemberPopUp_icon {
      width: 147rpx;
      height: 147rpx;
      position: absolute;
      top: 0;
      right: 0;
    }

  }
</style>
